<template>
    <div style="display: flex; height: calc(100vh - 220px)">
      <el-aside width="250px">
        <h3 style="margin-left: 30px;">通知信息</h3>
        <el-scrollbar>
          <el-menu :default-active="activeIndex" @select="handleSelect">
            <el-menu-item v-for="(notification, index) in notifications" :key="index" :index="index.toString()">
              <!-- 标题部分 -->
              <div class="menu-item-content">
                <span class="title">{{ notification.action==0?"警告消息":"封禁消息" }}[{{ notification.createTime }}]</span>
                <!-- 日期部分 -->
              </div>
            </el-menu-item>
          </el-menu>
        </el-scrollbar>
      </el-aside>
      <el-main>
        <div v-if="selectedNotification">
          <h2>{{ selectedNotification.action==0?"警告":"封禁" }}</h2>
          <p><strong>时间:</strong> {{ selectedNotification.createTime }}</p>
          <p>{{ selectedNotification.reason }}</p>
        </div>
        <div v-else>
          <p>请选择一个通知以查看详情。</p>
        </div>
      </el-main>
    </div>
  </template>

  <script setup>
  import { ref, reactive, getCurrentInstance, nextTick } from "vue"
  const { proxy } = getCurrentInstance();

  const api = {
    loadviolation: "/violation/loadDataList4User"
  }

  const notifications = ref([]);

  const activeIndex = ref('0');
  const selectedNotification = ref(null);

  const handleSelect = (index) => {
    activeIndex.value = index;
    selectedNotification.value = notifications.value[index];
  };

  const loadDataList = async () => {
    let result = await proxy.Request({
      url: api.loadviolation,
      params: {}
    })
    if (!result) {
      return;
    }
    notifications.value = result.data;
    // 默认选中第一个通知
    if (notifications.value.length > 0) {
      selectedNotification.value = notifications.value[0];
    }
  }
  loadDataList();
  </script>

  <style scoped>
  .el-aside {
    background-color: #f9fafc;
    border-right: 1px solid #dcdcdc;
  }

  .el-main {
    padding: 20px;
  }

  /* 调整菜单项的样式 */
  .el-menu-item {
    padding: 12px 20px;
  }

  .menu-item-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  /* 标题超出宽度时隐藏并显示省略号 */
  .title {
    max-width: 180px; /* 设置固定宽度 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: bold;
  }

  /* 日期部分 */
  .date {
    max-width: 180px; /* 设置固定宽度 */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #8492a6;
    font-size: 12px;
  }

  /* 主体内容样式 */
  h2 {
    margin-bottom: 10px;
  }

  p {
    line-height: 1.6;
  }
  </style>



